import io

# 想使用操作类文件对象的程序来操作文本或二进制字符串
def demo_1():
    s = io.StringIO()
    s.write('Hello kepler\n')
    print('This is a test', file=s)

def demo_2():
    s = io.StringIO('Hello\nWorld\n')
    print(s.read(4))
    print(s.read())

if __name__ == '__main__':
    # demo_1()
    demo_2()